package io.gitee.thghh.generate.core;

import com.mybatisflex.codegen.Generator;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.zaxxer.hikari.HikariDataSource;

public class Codegen {

    public static void main(String[] args) {
        //配置数据源
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl("jdbc:h2:./db/code;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;OLD_INFORMATION_SCHEMA=TRUE");
        dataSource.setUsername("root");
        dataSource.setPassword("code123");

        //创建配置内容，两种风格都可以。
        GlobalConfig globalConfig = createGlobalConfigUseStyle1();
        //GlobalConfig globalConfig = createGlobalConfigUseStyle2();

        //通过 datasource 和 globalConfig 创建代码生成器
        Generator generator = new Generator(dataSource, globalConfig);

        //生成代码
        generator.generate();
    }

    public static GlobalConfig createGlobalConfigUseStyle1() {
        //创建配置内容
        GlobalConfig globalConfig = new GlobalConfig();

        //设置根包
        globalConfig.setBasePackage("io.gitee.thghh.generate.core");

        //设置表前缀和只生成哪些表
        // globalConfig.("tb_");
        globalConfig.setUnGenerateTable("LIQUIBASE_CHANGE_LOG_LOCK", "LIQUIBASE_CHANGE_LOG");
        globalConfig.setGenerateTable("DATA_DICTIONARY");

        //设置生成 entity 并启用 Lombok
        globalConfig.setEntityWithLombok(true);
        globalConfig.setEntityGenerateEnable(true);
        globalConfig.setMapperGenerateEnable(true);
        globalConfig.setServiceGenerateEnable(true);
        globalConfig.setServiceImplGenerateEnable(true);
        globalConfig.setControllerGenerateEnable(true);
        globalConfig.setTableDefGenerateEnable(true);
        globalConfig.setMapperXmlGenerateEnable(true);
        globalConfig.setMapperAnnotation(true);

        globalConfig.setAuthor("pengzhikang");

        return globalConfig;
    }


}